/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.click.app.dao.hibernate;

import com.click.app.dao.CutDetailDao;
import com.click.app.model.CutDetail;
import com.click.app.model.CutProcess;
import com.click.app.model.Employee;
import java.util.Date;
import java.util.List;

/**
 *
 * @author ariel
 */
public class CutDetailDaoHibernate extends GenericDaoHibernate<CutDetail, Long> implements CutDetailDao{

    public CutDetailDaoHibernate() {
        super(CutDetail.class);
    }

    public List<CutDetail> findByCutProcess(CutProcess cutProcess) {
        return getHibernateTemplate().find("from CutDetail where cutProcess=?", cutProcess);
    }
    public List<CutDetail> getAllForModel(){
        return getHibernateTemplate().find("from CutDetail where quantityRealClothesCurrent > 0 ");
    }
    public List<CutDetail> findByEmployee(Employee employee) {
        return getHibernateTemplate().find("from CutDetail where cutProcess.employee=? AND currentAmount>0", employee);
    }
    public List<CutDetail> findByEmployeePeriod(Employee employee, Date initDate, Date endDate) {
        Object[] objects = {employee, initDate, endDate};
        return getHibernateTemplate().find("from CutDetail where cutProcess.employee=? and cutProcess.endDate Between ? And ? order by cutProcess.endDate", objects);
    }
    public List<CutDetail> getByModel(Long idMaterial, Long idModel, Long idModelSize){
        Object[] values={idModel, idModelSize, idMaterial};
        return getHibernateTemplate().find("from CutDetail where pantDesign.model.id=? AND pantDesign.modelSize.id=? AND pantDesign.material.id=? AND quantityRealClothesCurrent > 0 order by id ", values);
    }
    public List<CutDetail> findByPantDesign(Long idPantDesign){
        return getHibernateTemplate().find("from CutDetail where pantDesign.id=? ", idPantDesign);
    }
    public List<CutDetail> findByPantDesignAndLastDateAndNoCero(Long idPantDesign){
        return getHibernateTemplate().find("from CutDetail where pantDesign.id=? and currentAmount > 0 Order by cutProcess.endDate asc", idPantDesign);
    }
}
